﻿
Imports Microsoft.VisualBasic
Imports System.Data
Imports System.Data.SqlClient
Imports System.Configuration
Public Class lpii

    Public Shared tb As DataTable

    Public Function CrearTabla() As DataTable
        tb = New DataTable("ControlVotos")
        With tb.Columns
            .Add("Usuario", Type.GetType("System.String"))
            .Add("Encuesta", Type.GetType("System.String"))
            .Add("Pregunta", Type.GetType("System.String"))
        End With
        Return tb
    End Function


    Function Conectar() As SqlConnection

        Dim conexion As New SqlConnection _
                    (ConfigurationManager.ConnectionStrings("Conexion").ConnectionString)

        Return conexion
    End Function

    'Public Function IncrementarVisitas() As Boolean

    '    Dim conexion As SqlConnection
    '    conexion = Conectar()

    '    Dim comando As New SqlCommand("SP_INCREMENTARVISITAS", conexion)
    '    comando.CommandType = CommandType.StoredProcedure

    '    conexion.Open()
    '    comando.ExecuteNonQuery()
    '    conexion.Close()
    '    Liberamos(recursos)
    '    comando.Dispose()
    '    conexion.Dispose()

    'End Function


    Function Validar(ByVal usuario As String, ByVal encuesta As String, ByVal pregunta As String) As Boolean
        'Validamos que un producto no se agregue al detalle dos veces 
        Dim fila As DataRow
        For Each fila In tb.Rows
            If usuario = fila(0) And encuesta = fila(1) And pregunta = fila(2) Then
                Return False
            End If
        Next
        Return True
    End Function
End Class
